package com.sz.biz.common.approval;

import com.sz.common.base.i18n.I18nMessages;

/**
 * Package: com.sz.biz.common.approval <br>
 * Function: TODO: ADD FUNCTION <br>
 * Author: Charles. <br>
 * Date: 2017-04-17 15:06:00.
 */
public enum ApprovalStatus implements IApprovalStatus {
    Draft(0), Submitted(1), Approved(2), Online(3), Offline(4);

    private int value;

    ApprovalStatus(int val) {
        this.value = val;
    }

    public int value() {
        return this.value;
    }

    /**
     * @param status
     * @return
     */
    @Override
    public boolean isTransitive(IApprovalStatus status) {
        if (this.equals(Draft) && Submitted.equals(status)) {
            return true;
        }
        if (this.equals(Submitted) && (Draft.equals(status) || Approved.equals(status))) {
            return true;
        }
        if (this.equals(Approved) && Online.equals(status)) {
            return true;
        }
        if (this.equals(Online) && Offline.equals(status)) {
            return true;
        }
        return this.equals(Offline) && Online.equals(status);
    }

    @Override
    public int getValue() {
        return this.value;
    }

    @Override
    public String getName() {
        return this.name();
    }

    /**
     * 获取审核动作名称
     * @param i18nMessages
     * @param approval
     * @return
     */
    @Override
    public String getActionName(I18nMessages i18nMessages, Approval approval) {
        //TODO: 支持国际化，不要硬编码字符 --lqb
        String action = "";
        if (approval != null) {
            if (approval.getFromStatus() == ApprovalStatus.Draft.value()
                    && approval.getToStatus() == ApprovalStatus.Submitted.value()) {
                action = "提交审核";
            }
            if (approval.getFromStatus() == ApprovalStatus.Submitted.value()) {
                if (approval.getToStatus() == ApprovalStatus.Draft.value()) {
                    action = "打回草稿";
                }
                if (approval.getToStatus() == ApprovalStatus.Approved.value()) {
                    action = "审核通过";
                }
            }
            if (approval.getFromStatus() == ApprovalStatus.Approved.value()
                    && approval.getToStatus() == ApprovalStatus.Online.value()) {
                action = "启用";
            }
            if (approval.getFromStatus() == ApprovalStatus.Offline.value()
                    && approval.getToStatus() == ApprovalStatus.Online.value()) {
                action = "启用";
            }
            if (approval.getFromStatus() == ApprovalStatus.Online.value()
                    && approval.getToStatus() == ApprovalStatus.Offline.value()) {
                action = "停用";
            }
        }
        return action;
    }

}
